import request from '@/utils/request'

interface registerData {
  username: string
  password: string
}

export const registerAPI = (data: registerData) => {
  return request.post('/h5/user/register', data)
}

// 定义登录响应类型
interface serviceLoginResponse {
  code: number
  msg: string
  data: loginResponse
}
interface loginResponse {
  token: string
  currentAuthority: string
  status: string
  type: string
}
export const loginAPI = (data: registerData): Promise<serviceLoginResponse> => {
  return request.post('/h5/user/login', data)
}

// 定义用户信息响应类型
interface LoginUserResponseDTO {
  id: string
  username: string
  name: string
  avatar: string
  createdAt: string
  updatedAt: string
}

interface CurrentUserResponse {
  code: number
  message: string
  data: LoginUserResponseDTO
}

/**
 * 获取当前用户信息
 * @returns Promise<CurrentUserResponse>
 */
export const getCurrentUserAPI = (): Promise<CurrentUserResponse> => {
  return request.get('/h5/user/currentUser')
}

// 定义退出登录响应类型
interface LogoutResponse {
  code: number
  message: string
}

/**
 * 退出登录
 * @returns Promise<LogoutResponse>
 */
export const logoutAPI = (): Promise<LogoutResponse> => {
  return request.get('/h5/user/logout')
}
